﻿<%@ Page Language="C#" Theme="Register" %>

<%@ Import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  
    MembershipUser user;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Session["CaptchaImageText"] = GenerateRandomCode();
            ListItem defaultlist = new ListItem();
            defaultlist.Text = Resources.faContent.membershipDropDownListDefaultItem;
            defaultlist.Value = "0";

            try
            {
                user = Membership.GetUser(System.Web.HttpContext.Current.User.Identity.Name);
                ProfileCommon pf = Profile;
                pf = Profile.GetProfile(user.UserName);
                tbFirstName.Text = pf.Register.FirstName;
                tbLastName.Text = pf.Register.LastName;
                lusername.Text = pf.UserName;
            }
            catch (Exception ex)
            {
                Type javascript = "javascript".GetType();
                ClientScript.RegisterClientScriptBlock(javascript, "r2", "alert('" + Resources.faContent.changeAccoutMessageText + "')", true);
            }
        }

        Page.Title = Resources.faContent.changeAccountPageTitle;
        lFormNote.Text = Resources.faContent.changeAccountLFromNote;
        lLabelEmail.Text = Resources.faContent.changeAccountLEmail;
        lLabelFirstName.Text = Resources.faContent.membershipLFirstName;
        lLabelLastName.Text = Resources.faContent.membershipLLastName;
        lPersonalInfo.Text = Resources.faContent.membershipLPersonalInfo;
        lLabelNumImage.Text = Resources.faContent.membershipLNumImage;
        lLabelCaptchaLink.Text = Resources.faContent.membershipLCaptchaLink;
        btnForm.Text = Resources.faContent.changeAccountBText;
        rfvFirstName.ErrorMessage = Resources.faContent.membershipRFVDefaultMsg;
        rfvLastName.ErrorMessage = Resources.faContent.membershipRFVDefaultMsg;
    }
    private string GenerateRandomCode()
    {
        string s = "";
        Random rand = new Random();
        for (int i = 0; i <= 5; i++)
        {
            s = s + rand.Next(0, 10).ToString();
        }
        return s;
    }

    protected void btn_Click(object sender, EventArgs e)
    {
        lMessage.Style.Add("font", "bold 12px tahoma");
        string NoBotCode = Session["CaptchaImageText"].ToString();
        try
        {
            if (string.Compare(NoBotCode, tbNumImage.Text.Trim()) == 0)
            {
                ProfileCommon pf = (ProfileCommon)ProfileCommon.Create(lusername.Text);
                pf.Register.FirstName = tbFirstName.Text;
                pf.Register.LastName = tbLastName.Text;
                pf.Register.SendEmail = true;
                pf.Save();
                lMessage.ForeColor = System.Drawing.Color.Green;
                lMessage.Text = Resources.faContent.changeAccountSuccessMsg;
                pbody.Visible = false;
                btnForm.Visible = false;
            }
            else
            {
                lMessage.ForeColor = System.Drawing.Color.Red;
                lMessage.Text = Resources.faContent.membershipLMessageFail;
            }
        }
        catch (MembershipCreateUserException er)
        {
            lMessage.ForeColor = System.Drawing.Color.Red;
            lMessage.Text = Resources.faContent.membershipLMessageCreateUserError;
        }

    }

    [System.Web.Services.WebMethod]
    public static bool UserValidation(string Email)
    {
        return Membership.GetUser(Email) != null;
    }
    
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<script src="../script/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="../script/popupWindow.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        $('.captchalink').popupWindow({
            height: 600,
            width: 540,
            top: 50,
            left: 50
        });
    });

    function check(sender, args) {
        args.IsValid = (args.Value.length >= 4);
    }


</script>
<head id="Head1" runat="server">
</head>
<body>
    <form id="form1" runat="server">
        <div class="formSection">
            <div class="header">
                <span>
                    <asp:Literal runat="server" ID="lPersonalInfo" /></span></div>
           <div class="content">
                   <asp:Panel runat="server" ID="pbody">
                    <div id="mLogo" style="float: none; width: 100%;">
                        <p>
                            <asp:Literal runat="server" ID="lFormNote" />
                        </p>
                    </div>
                    <center>
                        <table>
                            <tr style="background: #eee;">
                                <td>
                                    <label>
                                        <asp:Literal runat="server" ID="lLabelEmail" /></label>
                                </td>
                                <td colspan="2">
                                    <asp:Label runat="server" ID="lusername" Style="font: bold 12px tahoma; color: Green;" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <label>
                                        <asp:Literal runat="server" ID="lLabelFirstName" /></label>
                                </td>
                                <td>
                                    <asp:TextBox runat="server" MaxLength="35" ValidationGroup="membership" ID="tbFirstName" />
                                </td>
                                <td>
                                    <asp:RequiredFieldValidator ValidationGroup="membership" runat="server" ID="rfvFirstName"
                                        Display="Dynamic" ControlToValidate="tbFirstName" SetFocusOnError="true"></asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <label>
                                        <asp:Literal runat="server" ID="lLabelLastName" /></label>
                                </td>
                                <td>
                                    <asp:TextBox runat="server" MaxLength="40" ValidationGroup="membership" ID="tbLastName" />
                                </td>
                                <td>
                                    <asp:RequiredFieldValidator ValidationGroup="membership" runat="server" ID="rfvLastName"
                                        Display="Dynamic" ControlToValidate="tbLastName" SetFocusOnError="true"></asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                        <td class="width">
                            <label>
                                <asp:Literal runat="server" ID="lLabelNumImage" /></label>
                        </td>
                        <td>
                            <asp:TextBox ValidationGroup="membership" runat="server" ID="tbNumImage" MaxLength="6"></asp:TextBox>
                        </td>
                        <td class="captcha">
                            <center>
                                <a class="captchalink" href="../captcha.htm">
                                    <asp:Literal runat="server" ID="lLabelCaptchaLink" /></a></center>
                            <asp:Image ID="imgCaptcha" Style="margin-top: 4px; border: solid 1px #acacac;" runat="server"
                                ImageUrl="../Captcha.aspx" />
                        </td>
                    </tr>
                    <tr>
                     <td colspan="2">
                      <asp:Button CssClass="submitbutton" OnClick="btn_Click" runat="server" ID="btnForm"
                ValidationGroup="membership" />
                     </td>
                    </tr>
                        </table>
                    </center>
                </div>
               </asp:Panel>
        </div>
        <center>
            <asp:Label runat="server" ID="lMessage" />
            <br />
            <br />
           
        </center>
    </form>
</body>
</html>
